/**
 * @Title: MailWebController.java
 * @Package com.chanjet.gongzuoquan.mail.rest.controller
 * @Description: 邮局操作web接口类
 * @author huqw
 * @date 2016年3月21日 上午8:48:42
 */
package com.ydd.wrench.server.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cellplus.comm.data.BaseDbcpDao;
import com.cellplus.comm.data.SqlFindField;
import com.cellplus.comm.util.*;
import com.ydd.wrench.bean.base.*;
import com.ydd.wrench.bean.base.Package;
import com.ydd.wrench.form.server.*;
import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import com.wrench.util.WrUtil;
import com.wrench.util.WrIdEnum;
import com.ydd.wrench.form.reqresp.RespMainPanelInfo;

/**
 * @author huqw
 *
 */
@Controller("mailWebController")
@RequestMapping("/ser")
public class MailWebController {

  protected final static Logger logger = LoggerFactory.getLogger(MailWebController.class);

  @Resource
  private LocalSettingService localSer;

  @Resource
  private MainService mService;

  @Resource
  private FormService formService;

  @Resource
  private UserService userSer;

  @Resource
  private CodeRuleService codeSer;

  @RequestMapping(value = "/initNew")
  public ModelAndView initNew(HttpServletRequest request) {

    String userId = CookieUtils.getInstance().getUserId(request);
    if (!userId.equals("admin")) {
      return null;
    }

    ModelAndView mv = new ModelAndView();
    mv.setViewName("initNew.jsp"); // 返回的文件名
    mv.addObject("domain", "abctest");

    mv.addObject("code", 1);
    mv.addObject("msg", "fff");
    return mv;
  }

  @RequestMapping(value = "/mainPanel")
  public ModelAndView mainPanel(HttpServletRequest request) {

    ModelAndView mv = new ModelAndView();
    mv.setViewName("design.jsp"); // 返回的文件名
    String userId = CookieUtils.getInstance().getUserOid(request);
    int userType = CookieUtils.getInstance().getUserType(request);
    
    RespMainPanelInfo mpdata = mService.getMainPanelData(userId,userType);
    BaseResult ret = null;
    if (mpdata != null) {
      ret = ErrorInfo.Sucess.toBaseResult().setMapData(mpdata.dataMap);
    } else {
      ret = ErrorInfo.Failed.toBaseResult();
    }

    
    Map<String, Object> mapData = userSer.getUsersInfoOne(userId);

    JSONObject obj = ImpJsonUtil.objOrMapToJson(ret.getMap(), null);
    mv.addObject("mpdata", obj);
    mv.addObject("curuser", mapData);
    return mv;
  }

  @RequestMapping(value = "/getNewId")
  @ResponseBody
  public Map<String, Object> getNewId(HttpServletRequest request,
      @RequestParam(value = "idType", required = true) String idType, HttpServletResponse response) throws Exception {
    
    String id = WrIdEnum.getNewId(idType);
    if ( ImpStringUtil.isEmpty(id)){
      return ErrorInfo.Failed.setMsg("获得标记失败:"+idType).toBaseResult().getMap();
    } else {
      return ErrorInfo.Sucess.toBaseResult().setMapData(id).getMap();
    }
  }
  
  /**
   * 登录页
   */
  @RequestMapping(value = "/toLogin")
  public ModelAndView login() {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("./login.jsp"); // 返回的文件名
    return mv;
  }
  
  @RequestMapping(value="/userTypeFailed")
  @ResponseBody
  public Map<String, Object> userTypeFailed(HttpServletRequest request){
    BaseResult bret = ErrorInfo.UserTypeFailed.toBaseResult();
    return bret.getMap();
  }

  @RequestMapping(value = "/logout")
  @ResponseBody
  public Map<String, Object> logout(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    CookieUtils.getInstance().removeCookie(request,response);
    return ErrorInfo.Sucess.toRetMapObj();
  }

  @RequestMapping(value = "/login")
  @ResponseBody
  public Map<String, Object> login(HttpServletRequest request,
      @RequestParam(value = "account", required = true) String account,
      @RequestParam(value = "password", required = true) String password,
      @RequestParam(value = "deviceType", required = true) String deviceType,
      @RequestParam(value = "loginType", required = false) String isRunUser, HttpServletResponse response)
      throws Exception {

    User user = new User();
    user.userName = account;
    user.pwd = MD5.crypt(password);
    
    // 判断是否初始化
    BaseResult bret = mService.checkInited();
    if (bret.isFailed()) {
      if (user.userName.equals("admin")) {
        user.userType = 2;
        user.oid = "ur1167804248514000001";
        String cookie = CookieUtils.getInstance().getCookieOrigValue(user);
        CookieUtils.getInstance().addCookie(cookie, request);
      }
      return bret.getMap();
    }

    BaseResult result = userSer.loginUser(user.userName, user.pwd, isRunUser, user);
    if (result.isFailed()) { // 用户名密码失败
      CookieUtils.getInstance().addCookie("", request);
      return result.getMap();
    }

    // 登陆成功, 返回是否第一次登陆
    String cookie = CookieUtils.getInstance().getCookieOrigValue(user);
    CookieUtils.getInstance().addCookie(cookie, request);
    return result.getMap();
  }

  @RequestMapping(value = "user/getUser")
  @ResponseBody
  public Map<String, Object> getUser(HttpServletRequest request,
      @RequestParam(value = "userId", required = true) String userId, HttpServletResponse response) throws Exception {

    List<Map<String, Object>> listData = userSer.getUsers(userId);
    if (listData == null) {
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setData("data", listData).getMap();
  }
  
  @RequestMapping(value = "user/getUser2")
  @ResponseBody
  public Map<String, Object> getUser2(HttpServletRequest request,
      @RequestParam(value = "userId", required = true ) String userId, 
      @RequestParam(value = "userType", required = false, defaultValue = "-1") int userType,
      @RequestParam(value = "withDept", required = false, defaultValue = "-1") int withDept, HttpServletResponse response) throws Exception {

    List<Map<String, Object>> listData = userSer.getUsers2(userId, userType);
    if (listData == null) {
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setData("data", listData).getMap();
  }

  @RequestMapping(value = "user/getCurUser")
  @ResponseBody
  public Map<String, Object> getCurUser(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    Map<String, Object> mapData = userSer.getUsersInfoOne(userId);
    if (mapData == null) {
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setMapData(mapData).getMap();
  }

  @RequestMapping(value = "user/design/addOrUpdateUser")
  @ResponseBody
  public Map<String, Object> addOrUpdateUser(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String str, HttpServletResponse response) throws Exception {

    User user = WrUtil.fromJson(User.class, str);
    return userSer.addOrUpdateUser(user).getMap();
  }
  
  @RequestMapping(value = "user/design/delUser")
  @ResponseBody
  public Map<String, Object> delUser(HttpServletRequest request,
      @RequestParam(value = "userId", required = true) String userId, HttpServletResponse response) throws Exception {

    BaseResult ret = userSer.deleteUser(userId);
    return ret.getMap();
  }
  
  @RequestMapping(value = "/form/run/delSubTableData")
  @ResponseBody
  public Map<String, Object> delSubTableData(HttpServletRequest request,
      @RequestParam(value = "did", required = true) String did,
      @RequestParam(value = "tableId", required = true) String tableId, HttpServletResponse response) throws Exception {

    BaseResult ret = formService.delSubTableData(tableId, did);
    return ret.getMap();
  }
  @RequestMapping(value = "user/getDept")
  @ResponseBody
  public Map<String, Object> getDept(HttpServletRequest request,
      @RequestParam(value = "deptId", required = true) String deptId, HttpServletResponse response) throws Exception {

    List<Map<String, Object>> listData = userSer.getDepts(deptId);
    List<Map<String, Object>> retData = WrUtil.makeDeptTree(listData);
    
    if (retData == null) {
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setData("data", retData).getMap();
  }
  
  @RequestMapping(value = "user/getDeptSubCode")
  @ResponseBody
  public Map<String, Object> getDeptSubCode(HttpServletRequest request,
      @RequestParam(value = "deptCode", required = true) Long deptCode, HttpServletResponse response) throws Exception {

    if ( deptCode == null ){
      return ErrorInfo.ParamFailed.toBaseResult().getMap();
    }
    
    long v = userSer.getDeptMaxSub(deptCode);
    
    if (v == -1) {
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setData("data", v).getMap();
  }
  
  @RequestMapping(value = "/form/design/addOrUpdatePack")
  @ResponseBody
  public Map<String, Object> addOrUpdatePack(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {
    JSONObject jobj = ImpJsonUtil.ParseJson(jsonObj);
    if ( jobj.has("oid") ){
      //do update
      Map<String, Object> mapObj = ImpJsonUtil.mapObjFromJson(jobj, null, null);
      return formService.addOrUpdatePackageByMapObj(mapObj).getMap();
    } else {
      Package pack = (Package) ImpJsonUtil.objFromJson2Str(jsonObj, Package.class, null, null, null);
      String userOid = CookieUtils.getInstance().getUserOid(request);
      pack.userId = userOid;
      return formService.addOrUpdatePackage(pack).getMap(); 
    }
  }

  @RequestMapping(value = "getPackList")
  @ResponseBody
  public Map<String, Object> getPackList(HttpServletRequest request,
      HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    int userType = CookieUtils.getInstance().getUserType(request);
    List<Map<String, Object>> retData = mService.getPackFormList(userId, userType);
    if ( retData == null){
      return ErrorInfo.Failed.toBaseResult().getMap();
    }else {
      return ErrorInfo.Sucess.toBaseResult().setMapData(retData).getMap();
    }
  }
  
    @RequestMapping(value = "getRightByUserForm")
  @ResponseBody
  public Map<String, Object> getRightByUserForm(HttpServletRequest request,
      @RequestParam(value = "deptUserId", required = true) String deptUserId,
      @RequestParam(value = "packFormId", required = true) String packFormId,
      HttpServletResponse response) throws Exception {

    Map<String, Object> retData = mService.getRightByUserForm(deptUserId, packFormId);
    WrUtil.makeRightSep(retData);
    if ( retData == null){
      return ErrorInfo.Failed.toBaseResult().getMap();
    }else {
      return ErrorInfo.Sucess.toBaseResult().setMapData(retData).getMap();
    }
  }
    
    @RequestMapping(value = "getRightAllByUserForm")
  @ResponseBody
  public Map<String, Object> getRightPackFormList(HttpServletRequest request,
      @RequestParam(value = "deptUserId", required = true) String deptUserId,
      HttpServletResponse response) throws Exception {

    return  mService.getRightPackFormList(deptUserId).getMap();
  }
        
  @RequestMapping(value = "user/design/addOrUpdateDept")
  @ResponseBody
  public Map<String, Object> addOrUpdateDept(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {

    Dept user = WrUtil.fromJson(Dept.class, jsonObj);
    return userSer.addOrUpdateDept(user).getMap();
  }
  
  @RequestMapping(value = "form/design/delPack")
  @ResponseBody
  public Map<String, Object> delPack(HttpServletRequest request,
      @RequestParam(value = "packId", required = true) String packId, HttpServletResponse response) throws Exception {

    BaseResult ret = formService.delPack(packId);
    return ret.getMap();

  }
  
  @RequestMapping(value = "user/design/delDept")
  @ResponseBody
  public Map<String, Object> delDept(HttpServletRequest request,
      @RequestParam(value = "deptId", required = true) String deptId, HttpServletResponse response) throws Exception {

    BaseResult ret = userSer.deleteDept(deptId);
    return ret.getMap();

  }
  
  @RequestMapping(value = "user/getDeptUser")
  @ResponseBody
  public Map<String, Object> getDeptUser(HttpServletRequest request,
      @RequestParam(value = "deptId", required = true) String deptId, HttpServletResponse response) throws Exception {

    BaseResult bret = ErrorInfo.Sucess.toBaseResult();
    List<Map<String, Object>> ret = userSer.getDeptUser(deptId);
    if ( ret == null ){
      bret = ErrorInfo.DbFailed.toBaseResult();
    } else {
      bret.setMapData(ret);
    }
    return bret.getMap();

  }
  
  @RequestMapping(value = "user/getRight")
  @ResponseBody
  public Map<String, Object> getRight(HttpServletRequest request,
      @RequestParam(value = "rightId", required = true) String rightId, HttpServletResponse response) throws Exception {

    List<Map<String, Object>> retData = userSer.getRight(rightId);
    if ( retData == null ){
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setMapData(retData).getMap();
  }
  
  @RequestMapping(value = "user/getRightPackFormSetting")
  @ResponseBody
  public Map<String, Object> getRightPackFormSetting(HttpServletRequest request,
      @RequestParam(value = "deptUserId", required = true) String deptUserId, HttpServletResponse response) throws Exception {

    List<Object> retData = userSer.getRightPackFormSetting(deptUserId);
    if ( retData == null ){
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().setMapData(retData).getMap();
  }
  
  @RequestMapping(value = "user/design/resetRightByUserForm")
  @ResponseBody
  public Map<String, Object> resetRightByUserForm(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {

    BaseResult retData = userSer.resetRightByUserForm(jsonObj);
    return retData.getMap();
  }
      
  @RequestMapping(value = "user/design/addOrUpdateRight")
  @ResponseBody
  public Map<String, Object> addOrUpdateRight(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String postObj, HttpServletResponse response) throws Exception {

    Right user = WrUtil.fromJson(Right.class, postObj);
    return userSer.addOrUpdateRight(user).getMap();
  }

  
  @RequestMapping(value = "user/design/delRightToUserForm")
  @ResponseBody
  public Map<String, Object> delRightToUserForm(HttpServletRequest request,
      @RequestParam(value = "deptUserId", required = true) String deptUserId, 
      @RequestParam(value = "packFormId", required = true) String packFormId, 
      HttpServletResponse response) throws Exception {

    BaseResult retData = userSer.deleteRightToUserForm(deptUserId, packFormId, null);
    return retData.getMap();
  }
      
  @SuppressWarnings("unchecked")
  @RequestMapping(value = "user/design/addRightToUserForm")
  @ResponseBody
  public Map<String, Object> addRightToUserForm(HttpServletRequest request,
      @RequestParam(value = "deptUserId", required = true) String deptUserId,
      @RequestParam(value = "packFormId", required = true) String packFormId,
      @RequestParam(value = "rightId", required = true) String rightId,
      HttpServletResponse response) throws Exception {

    Map<String, Object> mapData = ImpMapObjUtil.listToMapObj(ImpCollUtil.strsToList("rightId", "packFormId", "deptUserId" ), 
        ImpCollUtil.strsToListObj(rightId, packFormId, deptUserId));
    List<Map<String, Object>> listM = ImpMapObjUtil.objsToListM(mapData);
    int ret = userSer.addRightTo(RightToUserForm.getTbl(), listM);
    if ( ret != 1 ){
      return ErrorInfo.Failed.toBaseResult().getMap();
    }
    return ErrorInfo.Sucess.toBaseResult().getMap();
  }
    
  @RequestMapping(value = "/form/design/addOrUpdateForm")
  @ResponseBody
  public Map<String, Object> addOrUpdateForm(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {
    
    JSONObject jobj = ImpJsonUtil.ParseJson(jsonObj);
    if ( jobj.has("oid") ){
      //do update
      Map<String, Object> mapObj = ImpJsonUtil.mapObjFromJson(jobj, null, null);
      return formService.addOrUpdateFormByMapObj(mapObj).getMap();
    } else {
      Form form = (Form) ImpJsonUtil.objFromJson2Str(jsonObj, Form.class, null, null, null);
      String userOid = CookieUtils.getInstance().getUserOid(request);
      form.userId = userOid;
      return formService.addOrUpdateForm(form).getMap(); 
    }
    
  }

  @RequestMapping(value = "/form/getForm")
  @ResponseBody
  public Map<String, Object> getForm(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId, HttpServletResponse response) throws Exception {
    Map<String, Object> val =  formService.getForm(formId, true, true).getMap();
    return val;
  }

  @RequestMapping(value = "/form/getFormTmpl")
  @ResponseBody
  public Map<String, Object> getFormTmpl(HttpServletRequest request,
      @RequestParam(value = "tmplId", required = true) String tmplId, HttpServletResponse response) throws Exception {
    Map<String, Object> val =  formService.getFormTmpl(tmplId).toRetMapObj();
    return val;
  }

  @RequestMapping(value = "form/design/delForm")
  @ResponseBody
  public Map<String, Object> delForm(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId, HttpServletResponse response) throws Exception {

    BaseResult ret = formService.delForm(formId);
    return ret.getMap();

  }

  @RequestMapping(value = "/form/design/saveFormStyle")
  @ResponseBody
  public Map<String, Object> saveFormStyle(HttpServletRequest request,
      @RequestBody Map<String,Object> params,
      HttpServletResponse response) throws Exception {
    String formId = params.get("formId").toString();
    String styleData =params.get("styleData").toString();
    return formService.addOrUpdateFormStyle(formId, styleData, -1).getMap();
  }

  @RequestMapping(value = "/form/design/createTable")
  @ResponseBody
  public Map<String, Object> createTable(HttpServletRequest request,
      @RequestBody Map<String,Object> params, HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    String jsonObj = params.get("jsonObj").toString();
    return formService.createMDTable(userId, jsonObj).getMap();
  }

  @RequestMapping(value = "/form/run/addOrUpdateFormData")
  @ResponseBody
  public Map<String, Object> addOrUpdateData(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj,
      @RequestParam(value = "asNew", required = false) int newDataId,HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    return formService.addOrUpdateFormData(jsonObj, userId, newDataId).getMap();
  }

  @RequestMapping(value = "/form/design/addOrUpdateFormTmplData")
  @ResponseBody
  public Map<String, Object> addOrUpdateFormTmplData(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    return formService.addOrUpdateFormData(jsonObj, userId, 0).getMap();
  }

  @RequestMapping(value = "/form/design/addOrUpdateFormTmpl")
  @ResponseBody
  public Map<String, Object> addOrUpdateFormTmpl(HttpServletRequest request,
      @RequestParam(value = "jsonObj", required = true) String jsonObj, HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    JSONObject jobj = ImpJsonUtil.ParseJson(jsonObj);
    return formService.addOrUpdateFormTmpl(jobj, userId).toRetMapObj();
  }

  @RequestMapping(value = "/form/design/deleteDataset")
  @ResponseBody
  public Map<String, Object> deleteDataset(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId, HttpServletResponse response) throws Exception {
    String userId = CookieUtils.getInstance().getUserOid(request);
    return formService.deleteDataset(formId).toRetMapObj();
  }

  @RequestMapping(value = "/form/run/getFormData")
  @ResponseBody
  public Map<String, Object> getFromData(HttpServletRequest request,
      @RequestParam(value = "dataIndex", required = true) String dataindex, HttpServletResponse response) throws Exception {
    return formService.getFormData(dataindex).getMap();
  }

  @RequestMapping(value = "/form/getFormTmplList")
  @ResponseBody
  public Map<String, Object> getFormTmplList(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId,
      @RequestParam(value = "withImage", required = true) int withImage,
      @RequestParam(value = "pageNum", required = false, defaultValue = "0") int pageNum,
      @RequestParam(value = "perPageNum", required = false, defaultValue = "0") int perPageNum,
      HttpServletResponse response) throws Exception {
    return formService.getFormTmplList(formId, withImage ==1, pageNum, perPageNum).toRetMapObj();
  }

  @RequestMapping(value = "/form/getFormTmplImage")
  @ResponseBody
  public Map<String, Object> getFormTmplImage(HttpServletRequest request,
      @RequestParam(value = "tmplId", required = true) String tmplId, HttpServletResponse response) throws Exception {
    return formService.getFormTmplImage(tmplId).toRetMapObj();
  }

  @RequestMapping(value = "/form/run/getFormFindArr")
  @ResponseBody
  public Map<String, Object> getFormFindArr(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId){

    Map<String, Object> mapData =  formService.getFormFindArr(formId).toRetMapObj();
    return mapData;
  }

  @RequestMapping(value = "/form/run/findDataByFindArr")
  @ResponseBody
  public Map<String, Object> findDataByFindArr(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId,
      @RequestParam(value = "jsonObj", required = true) String jsonObj,
      @RequestParam(value = "pageNum", required = false, defaultValue = "0") int pageNum,
      @RequestParam(value = "perPageNum", required = false, defaultValue = "0") int perPageNum){
    String userOid = CookieUtils.getInstance().getUserOid(request);
    List<SqlFindField> findArr = ImpJsonUtil.objListFromJson(jsonObj, null, SqlFindField.class, null);
    return formService.findDataByFindArr(formId,userOid,findArr, pageNum, perPageNum).toRetMapObj();
  }
  
  @RequestMapping(value = "/form/run/findDataByDate")
  @ResponseBody
  public Map<String, Object> findDataByDate(HttpServletRequest request,
      @RequestParam(value = "formId", required = true) String formId, 
      @RequestParam(value = "dateNum", required = true) int dateNum,
      HttpServletResponse response) throws Exception {
    String userOid = CookieUtils.getInstance().getUserOid(request);
    return formService.findDataByDate(formId, dateNum, userOid).getMap();
  }
  
  @RequestMapping(value = "/user/changePwd")
  @ResponseBody
  public Map<String, Object> changePwd(HttpServletRequest request,
      @RequestParam(value = "oldPwd", required = true) String oldPwd, 
      @RequestParam(value = "pwd", required = true) String pwd, 
      HttpServletResponse response) throws Exception {
    String userOid = CookieUtils.getInstance().getUserOid(request);
    return userSer.changePwd(userOid, oldPwd, pwd).getMap();
  }
  
  @RequestMapping(value = "/setDb", method = RequestMethod.POST)
  @ResponseBody
  public Map<String, Object> setDb(HttpServletRequest request,
      @RequestParam(value = "str", required = true) String str, HttpServletResponse response) throws Exception {
    return localSer.initNew(str).getMap();
  }

  @RequestMapping(value = "/testdb", method = RequestMethod.POST)
  @ResponseBody
  public Map<String, Object> testdb(HttpServletRequest request,
      @RequestParam(value = "dbconn", required = true) String conn,
      @RequestParam(value = "dbtype", required = true) int dbtype, HttpServletResponse response) throws Exception {
    String isRet = BaseDbcpDao.isConnOk(conn);
    if (ImpStringUtil.isNotEmpty(isRet)) {
      return ErrorInfo.DbFailed.toBaseResult().setMsg(isRet).getMap();
    } else {
      return ErrorInfo.Sucess.toBaseResult().getMap();
    }
  }



  @RequestMapping(value = "/user/getEnterprise")
  @ResponseBody
  public Map<String, Object> getEnterprise(HttpServletRequest request, HttpServletResponse response) throws Exception {
    return userSer.getEnterpriseInfo().getMap();
  }
  
}
